import modules.modulefactory as ModuleFactory
import pygame

class TowerMenu():
    module_1 = None
    module_2 = None
    tower = None

    def __init__(self):
        pass
        
    def set_tower(self, tower):
        """
        Set the related tower for the menu. Also updates the information
        in the menu.
        """
        self.tower = tower
        self.module_1 = ModuleFactory.ModuleFactory().create_module( 
            self.tower.modules_level2[0] )
        self.module_2 = ModuleFactory.ModuleFactory().create_module( 
            self.tower.modules_level2[1] )
        self.module_1.rect.centerx = self.tower.rect.centerx + 20
        self.module_1.rect.centery = self.tower.rect.centery + 20
        self.module_2.rect.centerx = self.tower.rect.centerx + 60
        self.module_2.rect.centery = self.tower.rect.centery + 20        
        
    def handle_mouse_click(self, x, y):
        """
        Responds to mouse clicks in the menu.
        """
        print(self.module_1.rect)
        if self.module_1.rect.collidepoint(x,y):
            print('Click on module 1')
            self.tower.add_module( self.module_1 )
        elif self.module_2.rect.collidepoint(x,y):
            print('Click on module 2')
            self.tower.add_module( self.module_2 )
        
    def draw(self, screen):
        """
        The actual drawing of the menu.
        """
        background = pygame.Rect(
            self.tower.rect.centerx, self.tower.rect.centery, 200 ,200)
        pygame.draw.rect(screen, (0,0,0), background)        
        
        screen.blit(self.module_1.image, self.module_1.rect)
        screen.blit(self.module_2.image, self.module_2.rect)        